package com.demostic.demostic_test.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Path;
import android.graphics.PointF;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.view.MotionEventCompat;
import androidx.core.view.ViewCompat;

import com.accloud.cloudservice.AC;
import com.accloud.cloudservice.PayloadCallback;
import com.accloud.service.ACDeviceMsg;
import com.accloud.service.ACException;
import com.accloud.service.ACMsg;
import com.accloud.service.ACObject;
import com.accloud.utils.LogUtil;
import com.badoo.mobile.util.WeakHandler;
import com.demostic.demostic_test.R;
import com.demostic.demostic_test.base.BaseActivity;
import com.demostic.demostic_test.entity.DevicePropertyInfo_;
import com.demostic.demostic_test.entity.ForbiddenInfo;
import com.demostic.demostic_test.entity.Point;
import com.demostic.demostic_test.entity.RoomKeyCoordinate;
import com.demostic.demostic_test.entity.RoomNameInfo;
import com.demostic.demostic_test.entity.VirTualInfo;
import com.demostic.demostic_test.ui.MapEditView901;
import com.demostic.demostic_test.utils.DataUtils;
import com.demostic.demostic_test.utils.DeviceUtils;
import com.demostic.demostic_test.utils.DialogUtils;
import com.demostic.demostic_test.utils.SpUtils;
import com.demostic.demostic_test.utils.ToastUtils;
import com.google.gson.Gson;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class MapEditActivity901 extends BaseActivity implements View.OnClickListener {
    public static boolean isMopFbdEdit;
    public static boolean isOvaFbdEdit;
    public static boolean isPatEdit;
    public static boolean isPatNameEdit;
    public static boolean isUnifyMove;
    public static boolean isVirEdit;
    public static boolean isWhgEdit;
    public static int space = 6;
    private final int ADD_EMPTY_TO_NAMELIST = 1;
    private final int DELAYED_FINISH = 2;
    private final int DRA_ARE = 3;
    private final int MOP = 2;
    private final int OVA = 3;
    private final int PAT_ROM = 2;
    private final int QUERY = 1;
    private final int SEND = 2;
    private final String TAG = MapEditActivity901.class.getSimpleName();
    private final int VIR = 1;
    private final int VIR_FBD = 1;
    private TextView btn_bathroom;
    private TextView btn_bedroom;
    private TextView btn_cookroom;
    private TextView btn_custom;
    private TextView btn_liveroom;
    private PointF centerP;
    private Point chargeP;
    private Path chargePH;
    private int cleanMode;
    private int cleanTime;
    private Context context;
    private int curMapid;
    private MapEditView901 cvView;
    private long deviceId;
    private int editTag;
    private EditText edt_input_name;
    private Dialog exitEditdialog;
    private Dialog functionDialog;
    private int functionTag;
    private WeakHandler handler = new WeakHandler(new Handler.Callback() {
        /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass1 */

        @Override // android.os.Handler.Callback
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    MapEditActivity901.this.getRoomNameInfo();
                    return false;
                case 2:
                    DialogUtils.closeDialog(MapEditActivity901.this.loadingDialog);
                    ToastUtils.showToast(MapEditActivity901.this.context, MapEditActivity901.this.getString(R.string.vir_set_success));
                    MapEditActivity901.this.clear();
                    MapEditActivity901.this.finish();
                    return false;
                default:
                    return false;
            }
        }
    });
    private Point hostP;
    private Path hostPH;
    private byte[] hsbytes;
    private LayoutInflater inflater;
    private Dialog inputDialog;
    private boolean isFirstSelect;
    private boolean isGetRealMap;
    private ImageView iv_cancle;
    private ImageView iv_count;
    private ImageView iv_edit_exit;
    private ImageView iv_edit_save;
    private ImageView iv_mopfbd;
    private ImageView iv_ovafbd;
    private ImageView iv_pat;
    private ImageView iv_pat_name;
    private ImageView iv_vir;
    private ImageView iv_vir_fbd;
    private ImageView iv_vir_move;
    private ImageView iv_whg;
    private ImageView iv_whg_move;
    private LinearLayout ll_guaid;
    private LinearLayout ll_pat;
    private LinearLayout ll_virfbd;
    private LinearLayout ll_whg;
    private Dialog loadingDialog;
    private int[] nameCoordinate;
    private HashMap<Integer, RoomNameInfo> nameList;
    private LinearLayout.LayoutParams params;
    private String patName;
    private Dialog patnameDialog;
    private String physicalDeviceId;
    private byte[] realbytes;
    private RelativeLayout rl_edit_bottom;
    private RelativeLayout rl_edit_map;
    private RelativeLayout rl_mopfbd;
    private RelativeLayout rl_ovafbd;
    private RelativeLayout rl_pat;
    private RelativeLayout rl_pat_name;
    private RelativeLayout rl_vir;
    private RelativeLayout rl_vir_fbd;
    private RelativeLayout rl_vir_move;
    private RelativeLayout rl_whg;
    private RelativeLayout rl_whg_move;
    private int selectKey;
    private String serviceName;
    private String subdomain;
    private ArrayList<ForbiddenInfo> sucFbd_infoList;
    private ArrayList<VirTualInfo> sucVir_infoList;
    private ArrayList<ForbiddenInfo> sucWhg_infoList;
    private Dialog tipsDialog;
    private int total;
    private TextView tv_carpet_tips;
    private TextView tv_edit_tips;
    private TextView tv_input_confirm;
    private TextView tv_mopfbd;
    private TextView tv_ovafbd;
    private TextView tv_pat;
    private TextView tv_pat_name;
    private TextView tv_red_tips;
    private TextView tv_title;
    private TextView tv_vir;
    private TextView tv_vir_fbd;
    private TextView tv_vir_move;
    private TextView tv_whg;
    private TextView tv_whg_move;
    private int workMode;
    private int xMax;
    private int xMin;
    private int yMax;
    private int yMin;

    @Override // com.demostic.demostic_test.base.BaseActivity, android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_map_layout);
        EventBus.getDefault().register(this);
        getTag();
        getDeviceInfo();
        initView();
        if (this.editTag == 1 || this.editTag == 3) {
            getWorkStatus();
        } else {
            getDeviceProperty();
        }
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
        getVirtualAndForbiddenInfo();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getRoomNameInfo() {
        ACMsg req = new ACMsg();
        req.setName("getRoomInfo");
        req.put("device_id", Long.valueOf(this.deviceId));
        req.put("map_id", Integer.valueOf(this.curMapid));
        this.serviceName = DeviceUtils.getServiceName(this.subdomain);
        AC.sendToService("", this.serviceName, 1, req, new PayloadCallback<ACMsg>() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass2 */

            public void success(ACMsg resp) {
                MapEditActivity901.this.nameList.clear();
                LogUtil.e(MapEditActivity901.this.TAG, "getPatitionName success:" + resp);
                ArrayList<ACObject> data = (ArrayList) resp.get("data");
                if (data == null || data.size() <= 0) {
                    MapEditActivity901.this.addEmptyNameToHm();
                    return;
                }
                String str = data.get(0).getString("room_info");
                LogUtil.e(MapEditActivity901.this.TAG, "getPatitionName str:" + str);
                if (!TextUtils.isEmpty(str)) {
                    MapEditActivity901.this.getNameData(str, 1);
                } else {
                    MapEditActivity901.this.addEmptyNameToHm();
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                ToastUtils.showErrorToast(MapEditActivity901.this.context, e.getErrorCode());
                LogUtil.e(MapEditActivity901.this.TAG, "sendPatitionName error:" + e.toString());
            }
        });
    }

    private void getWorkStatus() {
        AC.bindMgr().sendToDeviceWithOption(this.subdomain, this.physicalDeviceId, new ACDeviceMsg(65, new byte[]{0}), 2, new PayloadCallback<ACDeviceMsg>() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass3 */

            public void success(ACDeviceMsg deviceMsg) {
                byte[] bt = deviceMsg.getContent();
                if (bt != null && bt.length > 0) {
                    int hsx = DataUtils.bytesToInt(new byte[]{bt[12], bt[13]}, 0);
                    int hsy = DataUtils.bytesToInt(new byte[]{bt[14], bt[15]}, 0);
                    int hostX = hsx + 750;
                    int hostY = 1500 - (hsy + 750);
                    int chargX = DataUtils.bytesToInt(new byte[]{bt[16], bt[17]}, 0) + 750;
                    int chargY = 1500 - (DataUtils.bytesToInt(new byte[]{bt[18], bt[19]}, 0) + 750);
                    LogUtil.e(MapEditActivity901.this.TAG, "test the charge and host position getWorkStatus:(" + hostX + "," + hostY + "),(" + chargX + "," + chargY + ")");
                    if (Math.abs(hostX) < 1500 && Math.abs(hostY) < 1500) {
                        MapEditActivity901.this.hostP.set(hostX, hostY);
                        MapEditActivity901.this.hostPH.reset();
                        MapEditActivity901.this.hostPH.addCircle((float) hostX, (float) hostY, 10.0f, Path.Direction.CW);
                    } else if (Math.abs(chargX) < 1500 && Math.abs(chargY) < 1500) {
                        MapEditActivity901.this.hostP.set(chargX, chargY);
                        MapEditActivity901.this.hostPH.reset();
                        MapEditActivity901.this.hostPH.addCircle((float) chargX, (float) chargY, 10.0f, Path.Direction.CW);
                    }
                    if (Math.abs(chargX) < 1500 && Math.abs(chargY) < 1500) {
                        MapEditActivity901.this.chargeP.set(chargX, chargY);
                        MapEditActivity901.this.chargePH.reset();
                        MapEditActivity901.this.chargePH.addCircle((float) chargX, (float) chargY, 10.0f, Path.Direction.CW);
                    }
                }
                MapEditActivity901.this.getDeviceProperty();
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                MapEditActivity901.this.getDeviceProperty();
                LogUtil.e(MapEditActivity901.this.TAG, "sendToDevice_WorkStatus error e " + e.toString());
            }
        });
    }

    private void getTag() {
        Bundle bundle;
        Intent intent = getIntent();
        if (intent != null && (bundle = intent.getExtras()) != null) {
            this.editTag = bundle.getInt("EDIT_TAG");
            this.workMode = bundle.getInt("work_mode");
            if (this.workMode == 1 || this.workMode == 2 || this.workMode == 9 || this.workMode == 11 || this.workMode == 17 || this.workMode == 18) {
                this.isGetRealMap = false;
            } else {
                this.isGetRealMap = true;
            }
        }
    }

    private void initView() {
        this.cleanMode = 6;
        this.cleanTime = 1;
        this.functionTag = 1;
        this.isFirstSelect = true;
        this.centerP = new PointF();
        this.chargeP = new Point();
        this.hostP = new Point();
        this.hostPH = new Path();
        this.chargePH = new Path();
        this.sucVir_infoList = new ArrayList<>();
        this.sucFbd_infoList = new ArrayList<>();
        this.sucWhg_infoList = new ArrayList<>();
        this.nameList = new HashMap<>();
        this.rl_edit_map = (RelativeLayout) findViewById(R.id.rl_edit_map);
        this.rl_edit_map.setBackgroundColor(getResources().getColor(R.color.color_f2));
        this.iv_edit_exit = (ImageView) findViewById(R.id.iv_edit_exit);
        this.iv_edit_save = (ImageView) findViewById(R.id.iv_edit_save);
        this.tv_title = (TextView) findViewById(R.id.tv_title);
        this.rl_edit_bottom = (RelativeLayout) findViewById(R.id.rl_edit_bottom);
        this.ll_virfbd = (LinearLayout) findViewById(R.id.ll_virfbd);
        this.rl_vir_move = (RelativeLayout) findViewById(R.id.rl_vir_move);
        this.iv_vir_move = (ImageView) findViewById(R.id.iv_vir_move);
        this.tv_vir_move = (TextView) findViewById(R.id.tv_vir_move);
        this.rl_vir_fbd = (RelativeLayout) findViewById(R.id.rl_vir_fbd);
        this.iv_vir_fbd = (ImageView) findViewById(R.id.iv_vir_fbd);
        this.tv_vir_fbd = (TextView) findViewById(R.id.tv_vir_fbd);
        this.ll_guaid = (LinearLayout) findViewById(R.id.ll_guaid);
        this.ll_pat = (LinearLayout) findViewById(R.id.ll_pat);
        this.rl_pat_name = (RelativeLayout) findViewById(R.id.rl_pat_name);
        this.iv_pat_name = (ImageView) findViewById(R.id.iv_pat_name);
        this.tv_pat_name = (TextView) findViewById(R.id.tv_pat_name);
        this.rl_pat = (RelativeLayout) findViewById(R.id.rl_pat);
        this.iv_pat = (ImageView) findViewById(R.id.iv_pat);
        this.tv_pat = (TextView) findViewById(R.id.tv_pat);
        this.ll_whg = (LinearLayout) findViewById(R.id.ll_whg);
        this.rl_whg_move = (RelativeLayout) findViewById(R.id.rl_whg_move);
        this.iv_whg_move = (ImageView) findViewById(R.id.iv_whg_move);
        this.tv_whg_move = (TextView) findViewById(R.id.tv_whg_move);
        this.rl_whg = (RelativeLayout) findViewById(R.id.rl_whg);
        this.iv_whg = (ImageView) findViewById(R.id.iv_whg);
        this.tv_whg = (TextView) findViewById(R.id.tv_whg);
        this.iv_count = (ImageView) findViewById(R.id.iv_count);
        this.tv_carpet_tips = (TextView) findViewById(R.id.tv_carpet_tips);
        this.tv_red_tips = (TextView) findViewById(R.id.tv_red_tips);
        this.cvView = new MapEditView901(this.context);
        this.params = new LinearLayout.LayoutParams(-1, -1);
        this.cvView.setLayoutParams(this.params);
        ((RelativeLayout) findViewById(R.id.rl_editmap)).addView(this.cvView);
        setListener();
        setTitleName();
        initEditLayout();
    }

    private void getDeviceInfo() {
        this.context = this;
        this.inflater = LayoutInflater.from(this.context);
        this.physicalDeviceId = SpUtils.getSpString(this.context, "physicalDeviceId");
        this.subdomain = SpUtils.getSpString(this.context, "subdomain");
        this.deviceId = SpUtils.getLong(this.context, "deviceId");
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getEvent(RoomKeyCoordinate info) {
        this.selectKey = info.getIdkey();
        this.nameCoordinate = info.getPresscoordinate();
        initPatNameDialog();
        LogUtil.e(this.TAG, "getEvent selectKey==:" + this.selectKey + "<->" + this.nameCoordinate[0] + "," + this.nameCoordinate[1] + ",");
    }

    private void setTitleName() {
        switch (this.editTag) {
            case 1:
                this.tv_title.setText(R.string.edit_menu_vir);
                return;
            case 2:
                this.tv_title.setText(R.string.edit_menu_patition);
                return;
            case 3:
                this.tv_title.setText(R.string.edit_menu_wherego);
                return;
            default:
                return;
        }
    }

    private void setListener() {
        this.iv_edit_exit.setOnClickListener(this);
        this.iv_edit_save.setOnClickListener(this);
        this.rl_vir_fbd.setOnClickListener(this);
        this.rl_vir_move.setOnClickListener(this);
        this.rl_pat.setOnClickListener(this);
        this.rl_pat_name.setOnClickListener(this);
        this.rl_whg.setOnClickListener(this);
        this.rl_whg_move.setOnClickListener(this);
        this.iv_count.setOnClickListener(this);
    }

    private void initEditLayout() {
        clear();
        switch (this.editTag) {
            case 1:
                showTipsDialog();
                isUnifyMove = true;
                this.ll_guaid.setVisibility(0);
                this.ll_virfbd.setVisibility(0);
                this.iv_vir_move.setSelected(true);
                this.tv_vir_move.setSelected(true);
                return;
            case 2:
                isPatEdit = true;
                this.ll_pat.setVisibility(0);
                this.iv_pat.setSelected(true);
                this.tv_pat.setSelected(true);
                return;
            case 3:
                isUnifyMove = true;
                this.ll_whg.setVisibility(0);
                this.iv_whg_move.setSelected(true);
                this.tv_whg_move.setSelected(true);
                return;
            default:
                return;
        }
    }

    private void showTipsDialog() {
        View view_tips = this.inflater.inflate(R.layout.dialog_edit_tips, (ViewGroup) null);
        this.tipsDialog = DialogUtils.showTipsDialog(this.context, view_tips);
        this.tipsDialog.setCanceledOnTouchOutside(false);
        this.tipsDialog.show();
        ((Button) view_tips.findViewById(R.id.bnt_know)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass4 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                MapEditActivity901.this.tipsDialog.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getDeviceProperty() {
        AC.deviceDataMgr().fetchCurrentProperty(this.subdomain, this.deviceId, new PayloadCallback<String>() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass5 */

            public void success(String s) {
                byte[] bt;
                byte[] data;
                DevicePropertyInfo_ dataInfo = (DevicePropertyInfo_) new Gson().fromJson(s, DevicePropertyInfo_.class);
                if (MapEditActivity901.this.editTag == 3) {
                    String area_setting = dataInfo.getClean_area_setting();
                    if (!TextUtils.isEmpty(area_setting) && (data = Base64.decode(area_setting, 0)) != null && data.length == 18) {
                        MapEditActivity901.this.getWhgAreaData(data);
                    }
                }
                String map_save = dataInfo.getMap_save();
                if (!TextUtils.isEmpty(map_save) && (bt = Base64.decode(map_save, 0)) != null && bt.length > 0) {
                    MapEditActivity901.this.curMapid = DataUtils.getMapID(bt[0], bt[1], bt[2], bt[3]);
                    if (MapEditActivity901.this.curMapid != 0) {
                        MapEditActivity901.this.getRecordMap(MapEditActivity901.this.curMapid);
                    } else if (MapEditActivity901.this.editTag == 1 && MapEditActivity901.this.isGetRealMap) {
                        MapEditActivity901.this.getRealTimeMap();
                    }
                    LogUtil.e(MapEditActivity901.this.TAG, "MapEdit getDeviceProperty success:" + bt.length + "," + MapEditActivity901.this.curMapid);
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                LogUtil.e(MapEditActivity901.this.TAG, "getDeviceProperty error==:" + e.toString());
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getWhgAreaData(byte[] bt) {
        MapEditView901.whgInfoList.clear();
        ArrayList<ForbiddenInfo> infos = DataUtils.decodeWhfData(bt, true);
        if (infos.size() > 0) {
            this.sucWhg_infoList.addAll(infos);
            MapEditView901.whgInfoList.addAll(infos);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getRecordMap(int mapid) {
        ACMsg req = new ACMsg();
        req.setName("getRecordMap");
        req.put("device_id", Long.valueOf(this.deviceId));
        req.put("map_id", Integer.valueOf(mapid));
        this.serviceName = DeviceUtils.getServiceName(this.subdomain);
        AC.sendToService("", this.serviceName, 1, req, new PayloadCallback<ACMsg>() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass6 */

            public void success(ACMsg resp) {
                LogUtil.e(MapEditActivity901.this.TAG, "MapEdit getRecordMap success:" + resp);
                if (resp.get("data") != null) {
                    ACObject acObject = (ACObject) ((ArrayList) resp.get("data")).get(0);
                    String strMap = acObject.getString("clean_slam");
                    String roadData = acObject.getString("clean_road");
                    MapEditActivity901.this.xMax = acObject.getInt("slam_x_max");
                    MapEditActivity901.this.xMin = acObject.getInt("slam_x_min");
                    MapEditActivity901.this.yMax = acObject.getInt("slam_y_max");
                    MapEditActivity901.this.yMin = acObject.getInt("slam_y_min");
                    MapEditActivity901.this.centerP.set((float) ((MapEditActivity901.this.xMax + MapEditActivity901.this.xMin) / 2), (float) (1500 - ((MapEditActivity901.this.yMax + MapEditActivity901.this.yMin) / 2)));
                    if (!TextUtils.isEmpty(strMap)) {
                        MapEditActivity901.this.hsbytes = Base64.decode(strMap, 0);
                        if (MapEditActivity901.this.editTag == 1) {
                            if (((MapEditActivity901.this.chargeP.x == 0 && MapEditActivity901.this.chargeP.y == 0) || (MapEditActivity901.this.hostP.x == 0 && MapEditActivity901.this.hostP.y == 0)) && !TextUtils.isEmpty(roadData)) {
                                Point lp = DataUtils.getLastPoint(Base64.decode(roadData, 0));
                                if (MapEditActivity901.this.chargeP.x == 0 && MapEditActivity901.this.chargeP.y == 0) {
                                    MapEditActivity901.this.chargeP.set(lp.x, lp.y);
                                    MapEditActivity901.this.chargePH.reset();
                                    MapEditActivity901.this.chargePH.addCircle((float) lp.x, (float) lp.y, 10.0f, Path.Direction.CW);
                                }
                                if (MapEditActivity901.this.hostP.x == 0 && MapEditActivity901.this.hostP.y == 0) {
                                    MapEditActivity901.this.hostP.set(lp.x, lp.y);
                                    MapEditActivity901.this.hostPH.reset();
                                    MapEditActivity901.this.hostPH.addCircle((float) lp.x, (float) lp.y, 10.0f, Path.Direction.CW);
                                }
                            }
                            if (MapEditActivity901.this.isGetRealMap) {
                                MapEditActivity901.this.getRealTimeMap();
                            } else {
                                MapEditActivity901.this.cvView.setEditData(MapEditActivity901.this.hsbytes, MapEditActivity901.this.realbytes, MapEditActivity901.this.centerP, MapEditActivity901.this.chargeP, MapEditActivity901.this.hostP, MapEditActivity901.this.xMax, MapEditActivity901.this.xMin, MapEditActivity901.this.yMax, MapEditActivity901.this.yMin);
                                MapEditActivity901.this.cvView.invalidate();
                            }
                        } else {
                            MapEditActivity901.this.cvView.setEditData(MapEditActivity901.this.hsbytes, MapEditActivity901.this.realbytes, MapEditActivity901.this.centerP, MapEditActivity901.this.chargeP, MapEditActivity901.this.hostP, MapEditActivity901.this.xMax, MapEditActivity901.this.xMin, MapEditActivity901.this.yMax, MapEditActivity901.this.yMin);
                            MapEditActivity901.this.cvView.invalidate();
                            MapEditActivity901.this.handler.sendEmptyMessageDelayed(1, 1000);
                        }
                    }
                    LogUtil.e(MapEditActivity901.this.TAG, "MapEdit getRecordMap success:" + MapEditActivity901.this.xMax + "," + MapEditActivity901.this.xMin + "," + MapEditActivity901.this.yMax + "," + MapEditActivity901.this.yMin + "," + MapEditActivity901.this.centerP.x + "," + MapEditActivity901.this.centerP.y);
                } else if (MapEditActivity901.this.editTag == 1 && MapEditActivity901.this.isGetRealMap) {
                    MapEditActivity901.this.getRealTimeMap();
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                LogUtil.e(MapEditActivity901.this.TAG, "MapEdit getRecordMap error:" + e.toString());
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getRealTimeMap() {
        ACMsg req = new ACMsg();
        req.setName("searchCleanRealTime");
        req.put("device_id", Long.valueOf(this.deviceId));
        AC.sendToService("", DeviceUtils.getServiceName(this.subdomain), 1, req, new PayloadCallback<ACMsg>() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass7 */

            public void success(ACMsg resp) {
                LogUtil.e(MapEditActivity901.this.TAG, "getRealTimeMap  getSlamMap success " + resp.toString());
                String strMap = resp.getString("slam_map");
                if (MapEditActivity901.this.centerP.x == 0.0f && MapEditActivity901.this.centerP.y == 0.0f) {
                    MapEditActivity901.this.xMax = resp.getInt("slam_x_max");
                    MapEditActivity901.this.xMin = resp.getInt("slam_x_min");
                    MapEditActivity901.this.yMax = resp.getInt("slam_y_max");
                    MapEditActivity901.this.yMin = resp.getInt("slam_y_min");
                    MapEditActivity901.this.centerP.set((float) ((MapEditActivity901.this.xMax + MapEditActivity901.this.xMin) / 2), (float) (1500 - ((MapEditActivity901.this.yMax + MapEditActivity901.this.yMin) / 2)));
                }
                if (!TextUtils.isEmpty(strMap)) {
                    MapEditActivity901.this.realbytes = Base64.decode(strMap, 0);
                }
                MapEditActivity901.this.cvView.setEditData(MapEditActivity901.this.hsbytes, MapEditActivity901.this.realbytes, MapEditActivity901.this.centerP, MapEditActivity901.this.chargeP, MapEditActivity901.this.hostP, MapEditActivity901.this.xMax, MapEditActivity901.this.xMin, MapEditActivity901.this.yMax, MapEditActivity901.this.yMin);
                MapEditActivity901.this.cvView.invalidate();
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                LogUtil.e(MapEditActivity901.this.TAG, "getRealTimeMap  getSlamMap error " + e.toString());
            }
        });
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_vir /* 2131755516 */:
                if (!this.iv_vir.isSelected()) {
                    isVirEdit = true;
                    isMopFbdEdit = false;
                    isOvaFbdEdit = false;
                    this.iv_vir.setSelected(true);
                    this.tv_vir.setSelected(true);
                    this.iv_mopfbd.setSelected(false);
                    this.tv_mopfbd.setSelected(false);
                    this.iv_ovafbd.setSelected(false);
                    this.tv_ovafbd.setSelected(false);
                    this.functionTag = 1;
                    this.functionDialog.dismiss();
                    return;
                }
                return;
            case R.id.rl_mopfbd /* 2131755519 */:
                if (!this.iv_mopfbd.isSelected()) {
                    isMopFbdEdit = true;
                    isVirEdit = false;
                    isOvaFbdEdit = false;
                    this.iv_mopfbd.setSelected(true);
                    this.tv_mopfbd.setSelected(true);
                    this.iv_vir.setSelected(false);
                    this.tv_vir.setSelected(false);
                    this.iv_ovafbd.setSelected(false);
                    this.tv_ovafbd.setSelected(false);
                    this.functionTag = 2;
                    this.functionDialog.dismiss();
                    return;
                }
                return;
            case R.id.rl_ovafbd /* 2131755522 */:
                if (!this.iv_ovafbd.isSelected()) {
                    isOvaFbdEdit = true;
                    isVirEdit = false;
                    isMopFbdEdit = false;
                    this.iv_ovafbd.setSelected(true);
                    this.tv_ovafbd.setSelected(true);
                    this.iv_vir.setSelected(false);
                    this.tv_vir.setSelected(false);
                    this.iv_mopfbd.setSelected(false);
                    this.tv_mopfbd.setSelected(false);
                    this.functionTag = 3;
                    this.functionDialog.dismiss();
                    return;
                }
                return;
            case R.id.rl_vir_fbd /* 2131755526 */:
                if (!this.iv_vir_fbd.isSelected()) {
                    isUnifyMove = false;
                    this.iv_vir_fbd.setSelected(true);
                    this.tv_vir_fbd.setSelected(true);
                    this.iv_vir_move.setSelected(false);
                    this.tv_vir_move.setSelected(false);
                    if (this.isFirstSelect) {
                        initFunctionSelectDialog();
                        this.isFirstSelect = false;
                        return;
                    }
                    switch (this.functionTag) {
                        case 1:
                            isVirEdit = true;
                            return;
                        case 2:
                            isMopFbdEdit = true;
                            return;
                        case 3:
                            isOvaFbdEdit = true;
                            return;
                        default:
                            return;
                    }
                } else {
                    initFunctionSelectDialog();
                    return;
                }
            case R.id.tv_input_confirm /* 2131755542 */:
                this.patName = this.edt_input_name.getText().toString();
                if (TextUtils.isEmpty(this.patName)) {
                    ToastUtils.showToast(this.context, getString(R.string.room_name_empty));
                    return;
                }
                this.inputDialog.dismiss();
                sendPatitionName();
                return;
            case R.id.iv_cancle /* 2131755545 */:
                this.patnameDialog.dismiss();
                this.cvView.resetPatitionMapData();
                return;
            case R.id.btn_liveroom /* 2131755546 */:
                if (!this.btn_liveroom.isSelected()) {
                    this.btn_liveroom.setSelected(true);
                    this.btn_bedroom.setSelected(false);
                    this.btn_cookroom.setSelected(false);
                    this.btn_bathroom.setSelected(false);
                    return;
                }
                return;
            case R.id.btn_bedroom /* 2131755547 */:
                if (!this.btn_bedroom.isSelected()) {
                    this.btn_bedroom.setSelected(true);
                    this.btn_liveroom.setSelected(false);
                    this.btn_cookroom.setSelected(false);
                    this.btn_bathroom.setSelected(false);
                    return;
                }
                return;
            case R.id.btn_cookroom /* 2131755548 */:
                if (!this.btn_cookroom.isSelected()) {
                    this.btn_cookroom.setSelected(true);
                    this.btn_bedroom.setSelected(false);
                    this.btn_liveroom.setSelected(false);
                    this.btn_bathroom.setSelected(false);
                    return;
                }
                return;
            case R.id.btn_bathroom /* 2131755549 */:
                if (!this.btn_bathroom.isSelected()) {
                    this.btn_bathroom.setSelected(true);
                    this.btn_cookroom.setSelected(false);
                    this.btn_bedroom.setSelected(false);
                    this.btn_liveroom.setSelected(false);
                    return;
                }
                return;
            case R.id.btn_custom /* 2131755550 */:
                this.patnameDialog.dismiss();
                initInputNameDialog();
                return;
            case R.id.tv_name_confirm /* 2131755551 */:
                if (this.btn_liveroom.isSelected()) {
                    this.patName = this.btn_liveroom.getText().toString();
                } else if (this.btn_bedroom.isSelected()) {
                    this.patName = this.btn_bedroom.getText().toString();
                } else if (this.btn_cookroom.isSelected()) {
                    this.patName = this.btn_cookroom.getText().toString();
                } else if (this.btn_bathroom.isSelected()) {
                    this.patName = this.btn_bathroom.getText().toString();
                }
                if (TextUtils.isEmpty(this.patName)) {
                    ToastUtils.showToast(this.context, getString(R.string.room_name_empty));
                    return;
                }
                this.patnameDialog.dismiss();
                sendPatitionName();
                return;
            case R.id.iv_edit_exit /* 2131755563 */:
                initExitVirtualDialog();
                return;
            case R.id.iv_edit_save /* 2131755564 */:
                if (this.editTag == 1) {
                    if (!judgeVirtualAndForbidden()) {
                        sendVirtualAndForbiddenData(MapEditView901.vtInfoList, MapEditView901.fbdInfoList);
                        return;
                    }
                    return;
                } else if (this.editTag == 2) {
                    if (!this.cvView.isExistCheckRoom()) {
                        ToastUtils.showToast(this.context, getString(R.string.choseroom_empty));
                        return;
                    } else {
                        sendCheckRoomData();
                        return;
                    }
                } else if (this.editTag != 3) {
                    return;
                } else {
                    if (MapEditView901.whgInfoList.size() == 0) {
                        ToastUtils.showToast(this.context, getString(R.string.no_whg_set));
                        return;
                    } else {
                        sendWheregoData(MapEditView901.whgInfoList);
                        return;
                    }
                }
            case R.id.iv_count /* 2131755571 */:
                if (this.cleanTime == 1) {
                    this.cleanTime = 2;
                    this.iv_count.setImageResource(R.drawable.clean_count2);
                    ToastUtils.showToast(this.context, getString(R.string.clean_count2_ts));
                    return;
                } else if (this.cleanTime == 2) {
                    this.cleanTime = 3;
                    this.iv_count.setImageResource(R.drawable.clean_count3);
                    ToastUtils.showToast(this.context, getString(R.string.clean_count3_ts));
                    return;
                } else if (this.cleanTime == 3) {
                    this.cleanTime = 1;
                    this.iv_count.setImageResource(R.drawable.clean_count1);
                    ToastUtils.showToast(this.context, getString(R.string.clean_count1_ts));
                    return;
                } else {
                    return;
                }
            case R.id.rl_vir_move /* 2131755576 */:
                if (!isUnifyMove) {
                    isUnifyMove = true;
                    this.iv_vir_move.setSelected(true);
                    this.tv_vir_move.setSelected(true);
                    isVirEdit = false;
                    isMopFbdEdit = false;
                    isOvaFbdEdit = false;
                    this.iv_vir_fbd.setSelected(false);
                    this.tv_vir_fbd.setSelected(false);
                    return;
                }
                return;
            case R.id.rl_pat_name /* 2131755581 */:
                if (!isPatNameEdit) {
                    isPatNameEdit = true;
                    this.iv_pat_name.setSelected(true);
                    this.tv_pat_name.setSelected(true);
                    isPatEdit = false;
                    this.iv_pat.setSelected(false);
                    this.tv_pat.setSelected(false);
                    this.cvView.resetPatitionMapData();
                    return;
                }
                return;
            case R.id.rl_pat /* 2131755584 */:
                if (!isPatEdit) {
                    isPatEdit = true;
                    isPatNameEdit = false;
                    this.iv_pat.setSelected(true);
                    this.tv_pat.setSelected(true);
                    this.iv_pat_name.setSelected(false);
                    this.tv_pat_name.setSelected(false);
                    this.cvView.resetPatitionMapData();
                    return;
                }
                return;
            case R.id.rl_whg_move /* 2131755587 */:
                if (!isUnifyMove) {
                    isUnifyMove = true;
                    isWhgEdit = false;
                    this.iv_whg_move.setSelected(true);
                    this.tv_whg_move.setSelected(true);
                    this.iv_whg.setSelected(false);
                    this.tv_whg.setSelected(false);
                    return;
                }
                return;
            case R.id.rl_whg /* 2131755590 */:
                if (!isWhgEdit) {
                    isWhgEdit = true;
                    isUnifyMove = false;
                    this.iv_whg.setSelected(true);
                    this.tv_whg.setSelected(true);
                    this.iv_whg_move.setSelected(false);
                    this.tv_whg_move.setSelected(false);
                    return;
                }
                return;
            default:
                return;
        }
    }

    private void initFunctionSelectDialog() {
        View view = this.inflater.inflate(R.layout.dialog_edit_function_select, (ViewGroup) null);
        this.functionDialog = DialogUtils.showPatNameDialog(this.context, view, 1);
        this.functionDialog.setCanceledOnTouchOutside(true);
        this.functionDialog.show();
        this.rl_vir = (RelativeLayout) view.findViewById(R.id.rl_vir);
        this.iv_vir = (ImageView) view.findViewById(R.id.iv_vir);
        this.tv_vir = (TextView) view.findViewById(R.id.tv_vir);
        this.rl_mopfbd = (RelativeLayout) view.findViewById(R.id.rl_mopfbd);
        this.iv_mopfbd = (ImageView) view.findViewById(R.id.iv_mopfbd);
        this.tv_mopfbd = (TextView) view.findViewById(R.id.tv_mopfbd);
        this.rl_ovafbd = (RelativeLayout) view.findViewById(R.id.rl_ovafbd);
        this.iv_ovafbd = (ImageView) view.findViewById(R.id.iv_ovafbd);
        this.tv_ovafbd = (TextView) view.findViewById(R.id.tv_ovafbd);
        this.rl_vir.setOnClickListener(this);
        this.rl_mopfbd.setOnClickListener(this);
        this.rl_ovafbd.setOnClickListener(this);
        setInitFunction();
        this.functionDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass8 */

            @Override // android.content.DialogInterface.OnDismissListener
            public void onDismiss(DialogInterface dialog) {
                if (dialog != null) {
                    switch (MapEditActivity901.this.functionTag) {
                        case 1:
                            MapEditActivity901.this.tv_red_tips.setText(MapEditActivity901.this.getString(R.string.draw_vir));
                            MapEditActivity901.this.tv_carpet_tips.setVisibility(8);
                            return;
                        case 2:
                            MapEditActivity901.this.tv_red_tips.setText(MapEditActivity901.this.getString(R.string.draw_fbd_mop));
                            MapEditActivity901.this.tv_carpet_tips.setVisibility(0);
                            return;
                        case 3:
                            MapEditActivity901.this.tv_red_tips.setText(MapEditActivity901.this.getString(R.string.draw_fbd_ova));
                            MapEditActivity901.this.tv_carpet_tips.setVisibility(8);
                            return;
                        default:
                            return;
                    }
                }
            }
        });
    }

    private void setInitFunction() {
        clearfunction();
        switch (this.functionTag) {
            case 1:
                isVirEdit = true;
                this.iv_vir.setSelected(true);
                this.tv_vir.setSelected(true);
                return;
            case 2:
                isMopFbdEdit = true;
                this.iv_mopfbd.setSelected(true);
                this.tv_mopfbd.setSelected(true);
                return;
            case 3:
                isOvaFbdEdit = true;
                this.iv_ovafbd.setSelected(true);
                this.tv_ovafbd.setSelected(true);
                return;
            default:
                return;
        }
    }

    private void clearfunction() {
        isVirEdit = false;
        isMopFbdEdit = false;
        isOvaFbdEdit = false;
        this.iv_vir.setSelected(false);
        this.tv_vir.setSelected(false);
        this.iv_mopfbd.setSelected(false);
        this.tv_mopfbd.setSelected(false);
        this.iv_ovafbd.setSelected(false);
        this.tv_ovafbd.setSelected(false);
    }

    private void initPatNameDialog() {
        View view_patname = this.inflater.inflate(R.layout.dialog_pat_name, (ViewGroup) null);
        this.patnameDialog = DialogUtils.showPatNameDialog(this.context, view_patname, 1);
        this.patnameDialog.setCanceledOnTouchOutside(false);
        this.patnameDialog.show();
        this.iv_cancle = (ImageView) view_patname.findViewById(R.id.iv_cancle);
        this.btn_liveroom = (TextView) view_patname.findViewById(R.id.btn_liveroom);
        this.btn_bedroom = (TextView) view_patname.findViewById(R.id.btn_bedroom);
        this.btn_cookroom = (TextView) view_patname.findViewById(R.id.btn_cookroom);
        this.btn_bathroom = (TextView) view_patname.findViewById(R.id.btn_bathroom);
        this.btn_custom = (TextView) view_patname.findViewById(R.id.btn_custom);
        this.iv_cancle.setOnClickListener(this);
        this.btn_liveroom.setOnClickListener(this);
        this.btn_bedroom.setOnClickListener(this);
        this.btn_cookroom.setOnClickListener(this);
        this.btn_bathroom.setOnClickListener(this);
        this.btn_custom.setOnClickListener(this);
        ((TextView) view_patname.findViewById(R.id.tv_name_confirm)).setOnClickListener(this);
    }

    private void initInputNameDialog() {
        View view_inname = this.inflater.inflate(R.layout.dialog_input_name, (ViewGroup) null);
        this.inputDialog = DialogUtils.showUnifyDialog(this.context, view_inname);
        this.inputDialog.show();
        this.edt_input_name = (EditText) view_inname.findViewById(R.id.edt_input_name);
        this.tv_input_confirm = (TextView) view_inname.findViewById(R.id.tv_input_confirm);
        this.tv_input_confirm.setOnClickListener(this);
        this.inputDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass9 */

            @Override // android.content.DialogInterface.OnCancelListener
            public void onCancel(DialogInterface dialog) {
                MapEditActivity901.this.cvView.resetPatitionMapData();
            }
        });
    }

    private boolean judgeVirtualAndForbidden() {
        if (MapEditView901.vtInfoList.size() > 0) {
            int size = MapEditView901.vtInfoList.size();
            for (int i = 0; i < size; i++) {
                if (MapEditView901.vtInfoList.get(i).isModifyed()) {
                    int[] virdata = MapEditView901.vtInfoList.get(i).getVirData();
                    if (DataUtils.judgeVirAndHostCharge(virdata[0], virdata[1], virdata[2], virdata[3], this.hostP, this.chargeP) != -1) {
                        ToastUtils.showToast(this.context, getString(R.string.send_comp));
                        return true;
                    }
                }
            }
        }
        if (MapEditView901.fbdInfoList.size() > 0) {
            int size2 = MapEditView901.fbdInfoList.size();
            for (int j = 0; j < size2; j++) {
                if (MapEditView901.fbdInfoList.get(j).isModifyed() && DataUtils.judgeFbdAndHostCharge(MapEditView901.fbdInfoList.get(j).getFbdData(), this.hostP, this.chargeP, this.hostPH, this.chargePH) != -1) {
                    ToastUtils.showToast(this.context, getString(R.string.send_comp));
                    return true;
                }
            }
        }
        return false;
    }

    private void sendPatitionName() {
        this.loadingDialog = DialogUtils.createLoadingDialog(this);
        this.nameList.get(Integer.valueOf(this.selectKey)).setRoomname(this.patName);
        this.nameList.get(Integer.valueOf(this.selectKey)).setNamecoordinate(this.nameCoordinate);
        String str = new Gson().toJson(this.nameList);
        ACMsg req = new ACMsg();
        req.setName("setRoomInfo");
        req.put("device_id", Long.valueOf(this.deviceId));
        req.put("map_id", Integer.valueOf(this.curMapid));
        req.put("room_info", str);
        this.serviceName = DeviceUtils.getServiceName(this.subdomain);
        AC.sendToService("", this.serviceName, 1, req, new PayloadCallback<ACMsg>() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass10 */

            public void success(ACMsg resp) {
                DialogUtils.closeDialog(MapEditActivity901.this.loadingDialog);
                MapEditActivity901.this.patName = "";
                MapEditActivity901.this.nameList.clear();
                LogUtil.e(MapEditActivity901.this.TAG, "test room name send suc resp:" + resp);
                String str = resp.getString("room_info");
                if (!TextUtils.isEmpty(str)) {
                    MapEditActivity901.this.getNameData(str, 2);
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                DialogUtils.closeDialog(MapEditActivity901.this.loadingDialog);
                MapEditActivity901.this.cvView.resetPatitionMapData();
                LogUtil.e(MapEditActivity901.this.TAG, "sendPatitionName error:" + e.toString());
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getNameData(String str, int tag) {
        try {
            JSONObject jsonObject = new JSONObject(str);
            Iterator<String> iterator = jsonObject.keys();
            while (iterator.hasNext()) {
                String key = iterator.next();
                JSONObject object = (JSONObject) jsonObject.get(key);
                String name = object.getString("roomname");
                JSONArray array = object.getJSONArray("namecoordinate");
                RoomNameInfo info = new RoomNameInfo();
                info.setRoomname(name);
                if (array == null || array.length() <= 0) {
                    info.setNamecoordinate(new int[0]);
                } else {
                    info.setNamecoordinate(new int[]{array.getInt(0), array.getInt(1)});
                }
                this.nameList.put(Integer.valueOf(key), info);
                LogUtil.e(this.TAG, "getPatitionName success data:" + key + "," + name + "," + this.nameList.size());
            }
            if (tag == 1) {
                addEmptyNameToHm();
            } else if (tag == 2) {
                this.cvView.resetPatitionMapData();
            }
            MapEditView901.setRoomName(this.nameList);
            this.cvView.invalidate();
        } catch (JSONException e) {
            LogUtil.e(this.TAG, "JSONException e = " + e.toString());
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void addEmptyNameToHm() {
        if (MapEditView901.rmidHm != null && MapEditView901.rmidHm.size() > 0) {
            for (Map.Entry<Integer, Boolean> entry : MapEditView901.rmidHm.entrySet()) {
                int key = entry.getKey().intValue();
                LogUtil.e(this.TAG, "addEmptyNameToHm:" + key);
                RoomNameInfo info = new RoomNameInfo();
                info.setRoomname("");
                info.setNamecoordinate(new int[0]);
                if (key == 2 || key == 11) {
                    key = 11;
                }
                if (!this.nameList.containsKey(Integer.valueOf(key))) {
                    this.nameList.put(Integer.valueOf(key), info);
                }
            }
        }
    }

    private void initExitVirtualDialog() {
        View view_exit = this.inflater.inflate(R.layout.dialog_exit_sp,  null);
        this.exitEditdialog = DialogUtils.showUnifyDialog(this.context, view_exit);
        this.exitEditdialog.show();
        this.exitEditdialog.setCanceledOnTouchOutside(false);
        ((TextView) view_exit.findViewById(R.id.tv_exitedit_cancel)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass11 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                MapEditActivity901.this.exitEditdialog.dismiss();
            }
        });
        ((TextView) view_exit.findViewById(R.id.tv_exitedit_confirm)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass12 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                MapEditActivity901.this.exitEditdialog.dismiss();
                if (MapEditActivity901.this.editTag == 1) {
                    MapEditActivity901.this.sendVirtualAndForbiddenData(MapEditActivity901.this.sucVir_infoList, MapEditActivity901.this.sucFbd_infoList);
                } else {
                    MapEditActivity901.this.finish();
                }
            }
        });
    }

    private void sendCheckRoomData() {
        this.loadingDialog = DialogUtils.createLoadingDialog(this);
        byte[] bt = new byte[6];
        bt[4] = (byte) this.cleanMode;
        bt[5] = (byte) this.cleanTime;
        for (Map.Entry<Integer, Boolean> entry : MapEditView901.rmidHm.entrySet()) {
            int key = entry.getKey().intValue();
            if (entry.getValue().booleanValue()) {
                if (key == 2 || key == 11) {
                    this.total++;
                } else {
                    this.total += 1 << (key - 11);
                }
            }
        }
        if (this.total != 0) {
            bt[0] = (byte) ((this.total & ViewCompat.MEASURED_STATE_MASK) >> 24);
            bt[1] = (byte) ((this.total & 16711680) >> 16);
            bt[2] = (byte) ((this.total & MotionEventCompat.ACTION_POINTER_INDEX_MASK) >> 8);
            bt[3] = (byte) (this.total & 255);
        }
        sendCheckRoom(new ACDeviceMsg(71, bt), this.physicalDeviceId);
    }

    private void sendCheckRoom(ACDeviceMsg deviceMsg, String physicalDeviceId2) {
        AC.bindMgr().sendToDeviceWithOption(this.subdomain, physicalDeviceId2, deviceMsg, 2, new PayloadCallback<ACDeviceMsg>() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass13 */

            public void success(ACDeviceMsg acDeviceMsg) {
                MapEditActivity901.this.total = 0;
                MapEditActivity901.this.handler.sendEmptyMessageDelayed(2, 2000);
                LogUtil.e(MapEditActivity901.this.TAG, "send data success," + acDeviceMsg.toString());
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                MapEditActivity901.this.total = 0;
                DialogUtils.closeDialog(MapEditActivity901.this.loadingDialog);
                ToastUtils.showToast(MapEditActivity901.this.context, MapEditActivity901.this.getString(R.string.vir_set_failed));
                LogUtil.e(MapEditActivity901.this.TAG, "send data failed:" + e.toString());
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void sendVirtualAndForbiddenData(final ArrayList<VirTualInfo> virInfo, final ArrayList<ForbiddenInfo> fbdInfo) {
        this.loadingDialog = DialogUtils.createLoadingDialog(this);
        new Thread(new Runnable() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass14 */

            @Override // java.lang.Runnable
            public void run() {
                MapEditActivity901.this.sendToDeviceWithOptionVirAndFbdData(new ACDeviceMsg(89, DataUtils.encodeVirFbdData(virInfo, fbdInfo)), MapEditActivity901.this.physicalDeviceId);
            }
        }).start();
    }

    private void sendWheregoData(final ArrayList<ForbiddenInfo> list) {
        this.loadingDialog = DialogUtils.createLoadingDialog(this);
        new Thread(new Runnable() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass15 */

            @Override // java.lang.Runnable
            public void run() {
                MapEditActivity901.this.sendToDeviceWithOptionVirAndFbdData(new ACDeviceMsg(94, DataUtils.encodeWhgData(list)), MapEditActivity901.this.physicalDeviceId);
            }
        }).start();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void sendToDeviceWithOptionVirAndFbdData(ACDeviceMsg acDeviceMsg, String physicalDeviceId2) {
        AC.bindMgr().sendToDeviceWithOption(this.subdomain, physicalDeviceId2, acDeviceMsg, 2, new PayloadCallback<ACDeviceMsg>() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass16 */

            public void success(ACDeviceMsg acDeviceMsg) {
                MapEditActivity901.this.handler.sendEmptyMessageDelayed(2, 3000);
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                DialogUtils.closeDialog(MapEditActivity901.this.loadingDialog);
                ToastUtils.showToast(MapEditActivity901.this.context, MapEditActivity901.this.getString(R.string.vir_set_failed));
                LogUtil.e(MapEditActivity901.this.TAG, "send data failed:" + e.toString());
            }
        });
    }

    private void getVirtualAndForbiddenInfo() {
        ACMsg req = new ACMsg();
        req.setName("getForbidAreaInfo");
        req.put("device_id", Long.valueOf(this.deviceId));
        AC.sendToService("", DeviceUtils.getServiceName(this.subdomain), 1, req, new PayloadCallback<ACMsg>() {
            /* class com.demostic.demostic_test.activity.MapEditActivity901.AnonymousClass17 */

            public void success(ACMsg resp) {
                LogUtil.e(MapEditActivity901.this.TAG, "query Virtual and Forbidden success:" + resp.toString());
                ArrayList<ACObject> data = (ArrayList) resp.get("data");
                if (data != null && data.size() > 0) {
                    String str = data.get(0).getString("forbid_area_setting");
                    if (!TextUtils.isEmpty(str)) {
                        byte[] bt = Base64.decode(str, 0);
                        MapEditActivity901.this.sucVir_infoList.clear();
                        MapEditActivity901.this.sucFbd_infoList.clear();
                        MapEditView901.vtInfoList.clear();
                        MapEditView901.fbdInfoList.clear();
                        ArrayList<VirTualInfo> virTualInfos = DataUtils.decodeVirData(bt, true);
                        if (virTualInfos.size() > 0) {
                            MapEditView901.vtInfoList.addAll(virTualInfos);
                            MapEditActivity901.this.addToNewListVir(MapEditView901.vtInfoList, MapEditActivity901.this.sucVir_infoList);
                        }
                        ArrayList<ForbiddenInfo> forbiddenInfos = DataUtils.decodeFbdData(bt, true);
                        if (forbiddenInfos.size() > 0) {
                            MapEditActivity901.this.sucFbd_infoList.addAll(forbiddenInfos);
                            MapEditView901.fbdInfoList.addAll(forbiddenInfos);
                        }
                        MapEditActivity901.this.cvView.invalidate();
                    }
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                LogUtil.e(MapEditActivity901.this.TAG, "query Virtual and Forbidden error:" + e.toString());
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void addToNewListVir(ArrayList<VirTualInfo> srcList, ArrayList<VirTualInfo> dstList) {
        dstList.clear();
        if (srcList.size() > 0) {
            int size = srcList.size();
            for (int i = 0; i < size; i++) {
                int[] virData = srcList.get(i).getVirData();
                VirTualInfo info = new VirTualInfo();
                info.setVirData((int[]) virData.clone());
                dstList.add(info);
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void clear() {
        isUnifyMove = false;
        isVirEdit = false;
        isMopFbdEdit = false;
        isOvaFbdEdit = false;
        isPatEdit = false;
        isPatNameEdit = false;
        isWhgEdit = false;
        this.iv_vir_move.setSelected(false);
        this.tv_vir_move.setSelected(false);
        this.iv_vir_fbd.setSelected(false);
        this.tv_vir_fbd.setSelected(false);
        this.iv_pat.setSelected(false);
        this.tv_pat.setSelected(false);
        this.iv_pat_name.setSelected(false);
        this.tv_pat_name.setSelected(false);
        this.iv_whg.setSelected(false);
        this.tv_whg.setSelected(false);
        this.iv_whg_move.setSelected(false);
        this.tv_whg_move.setSelected(false);
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }

    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onBackPressed() {
        initExitVirtualDialog();
    }
}
